*--------------------------------------------------------------; * Ratio estimate of the population mean and total, and ; * unbiased estimate of the population total for a single- ; * stage cluster sample. Data is assumed to be in the ; * form of cluster totals. Also computes variance ; * estimates s(r)^2 and s(t)^2. ; * sample = optional name of sample data set ; * npop = number of clusters in population ; * n = number of cluster in sample ; * response= response variable in form of cluster totals ; * param = parameter to be estimated ; * mi = number of elements per cluster in sample ; * mbar = Optional mean cluster size ; * fpc = 1, causes f.p.c. to be one. ; *--------------------------------------------------------------; %macro est_cl1(sample=,setup=,npop=,n=,response=,param=,mi=,m=, mbar=,fpc=); %if %length(&sample) = 0 %then %let sample = %str(sample); %if %length(&npop) = 0 %then %let npop = %str(npop); %if %length(&fpc) > 0 %then %do; %if %length(&mbar) = 0 %then %let mbar = %str(ave_m_); %end; %else %do; %if %length(&mbar) = 0 %then %do; %if %length(&m) > 0 %then %let mbar = %str(&m/&npop); %else %let mbar = %str(ave_m_); %end; %end; data est_; set &sample( keep = &mi &response); cp_ = &mi*&response; proc means data = est_ noprint; var &response &mi cp_; output out = mux_ mean = ybar_ ave_m_ sum = sumy_ sumx_ sumxy_ n = n_ css = ssyy_ ssxx_; data est_; %if %length(&setup) > 0 %then %do; merge mux_ &setup; %end; %else %do; set mux_; %end; mu_hat_ = sumy_/sumx_; ssxy_ = sumxy_ - sumx_*sumy_/n_; sc_ = (ssyy_ + mu_hat_**2*ssxx_ - 2*mu_hat_*ssxy_ )/(n_-1); %if %length(&fpc) > 0 %then %do; var_mu_ = sc_/(n_*(&mbar)**2); std_mu_ = sqrt(var_mu_); bnd_mu_ = 2*std_mu_; st_ = ssyy_/(n_-1); %end; %else %do; fpc_ = (&npop - n_)/&npop; var_mu_ = fpc_*sc_/(n_*(&mbar)**2); std_mu_ = sqrt(var_mu_); bnd_mu_ = 2*std_mu_; st_ = ssyy_/(n_-1); tau_hat_ = &npop*(&mbar)*mu_hat_; std_tau_ = &npop*(&mbar)*std_mu_; bnd_tau_ = 2*std_tau_; tau_unb_ = &npop*sumy_/n_; var_unb_ = &npop*(&npop - n_)*st_/n_; std_unb_ = sqrt(var_unb_); bnd_unb_ = 2*std_unb_; %end; %if %index(%upcase(¶m),MEAN) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Ratio Estimate of Population Mean'; title2 'Single-stage Cluster Design'; title3 "Response Variable = &response"; label mu_hat_ = 'Estimate'; label std_mu_ = 'Standard*Error'; label bnd_mu_ = 'Bound'; label sc_ = 's(c)^2'; var mu_hat_ std_mu_ bnd_mu_ sc_; %end; %if %index(%upcase(¶m),TOTAL) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Ratio Estimate of the Population Total'; title2 'Single-stage Cluster Design'; title3 "Response Variable = &response"; label tau_hat_ = 'Estimate'; label std_tau_ = 'Standard*Error'; label bnd_tau_ = 'Bound'; label sc_ = 's(c)^2'; var tau_hat_ std_tau_ bnd_tau_ sc_; %end; %if %index(%upcase(¶m),UNBIASED) > 0 %then %do; proc print data = est_ noobs split='*'; title1 'Unbiased Estimate of the Population Total'; title2 '(Does not Depend on M)'; title3 'Single-stage Cluster Design'; title4 "Response Variable = &response"; label tau_unb_ = 'Estimate'; label std_unb_ = 'Standard*Error'; label bnd_unb_ = 'Bound'; label st_ = 's(t)^2'; var tau_unb_ std_unb_ bnd_unb_ st_; %end; run; title; %mend est_cl1;